import dynamic from 'dva/dynamic';

// wrapper of dynamic
const dynamicWrapper = (app, models, component) => dynamic({
  app,
  models: () => models.map(m => import(`../models/${m}.js`)),
  component,
});

// nav data
export const getNavData = app => [
  {
    component: dynamicWrapper(app, ['user', 'login'], () => import('../layouts/BasicLayout')),
    layout: 'BasicLayout',
    name: '首页', // for breadcrumb
    path: '/',
    children: [
      {
        name: '书包柜', // 页面名称，会展示在菜单栏中
        icon: 'dashboard', // 页面图标，会展示在菜单栏中
        path: 'box', // 匹配的路由
        children: [
          {
            name: '书包柜获取时间',
            path: 'time',
            component: dynamicWrapper(app, ['time'], () => import('../routes/Box/Time')),
          },
          {
            name: '获取书包柜',
            path: 'getbox',
            component: dynamicWrapper(app, ['getbox'], () => import('../routes/Box/GetBox')),
          },
          {
            name: '查询我的书包柜',
            path: 'inquirebox',
            component: dynamicWrapper(app, ['inquirebox'], () => import('../routes/Box/InquireBox')),
          },
        ],
      },
      {
        name: '账户',
        path: 'user',
        icon: 'user',
        children: [
          {
            name: '登录',
            path: 'login',
            component: dynamicWrapper(app, ['login'], () => import('../routes/User/Login')),
          },
        ],
      },
    ],
  },
];

